﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContentList.aspx.cs" Inherits="background.Manager.Content.ContentList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../Styles/index.css" rel="stylesheet" />
    <script src="../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../Scripts/layer/layer.js"></script>

    <script type="text/javascript">
        function changeOrder(obj) {
            $.post("Action/content.ashx", { action: "changeOrder", order: $(obj).val(), id: $(obj).attr("data-id") }, function (ret) {
                if (!ret) {
                    layer.msg("排序保存失败");
                }
            })
        }
        function massDelete() {
            var d = new Array();
            $("input[name='idbox']:checked").each(function () { d.push($(this).val()); })
            if (d.length == 0) { layer.msg("请选择要删除的项"); return; }

            if (confirm("确定要删除所选项吗？")) {
                $.post("Action/content.ashx", { action: "delete", idList: d.join(',') }, function (ret) {
                    if (ret) {
                        layer.msg("删除成功，2秒后自动刷新页面", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                    } else {
                        layer.msg("对不起删除失败，稍后再试", { icon: 2 });
                    }
                })
            }
        }
        function deletes(id) {
            if (confirm("确定要删除吗？")) {
                $.post("Action/content.ashx", { action: "delete", idList: id }, function (ret) {
                    if (ret) {
                        layer.msg("删除成功，2秒后自动刷新页面", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                    } else {
                        layer.msg("对不起删除失败，稍后再试", { icon: 2 });
                    }
                })
            }
        }
        function checkboxAll(obj) {
            $("input[name='idbox']").attr("checked", $(obj).is(":checked"));
        }
        function changeType() {
            window.location.href = "?group=" + $("#group option:selected").val() + "&title=" + $("#titlekey").val();
        }
    </script>
</head>
<body>
    <div class="top">
        <strong>文章列表</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <div>
            <div class="tool_search">
                <input type="button" class="sbtn" value="发布" onclick="window.location.href = 'addContent.aspx?actionType=add&id=<%=Request["group"]%>'" />&nbsp;&nbsp;<input type="button" class="sbtn" value="批量删除" onclick="    massDelete()" />
                &nbsp;&nbsp;
                    <% System.Data.DataTable group=Codes.ContentGroup.getList(1, 9999); %>
                <select id="group" class="text" onchange="changeType()" style="width: 150px">
                    <option value="" data-type="">--全部--</option>
                    <% foreach(System.Data.DataRow dr in group.Rows) {%>
                    <option value="<%=dr["id"] %>" <%=string.IsNullOrEmpty(Request["group"])?"":(Request["group"].ToString()==dr["id"].ToString()?"selected='selected'":"") %> data-type="<%=dr["contentType"] %>"><%=dr["title"] %><%=dr["state"].ToString()=="0"?"(禁用)":"" %></option>
                    <%} %>
                </select>
                &nbsp;关键字：<input type="text" id="titlekey" class="text" placeholder="键入标题关键词" value="<%=Request["title"] %>" />&nbsp;<input type="button" class="sbtn" onclick="changeType()" value="查询" />
            </div>
            <table border="0" cellpadding="0" cellspacing="0" class="listtable">
                <tr>
                    <th class="th" style="width: 20px">
                        <input type="checkbox" onchange="checkboxAll(this)" /></th>
                    <th class="th">所属分类</th>
                    <th class="th">文章标题</th>
                    <th class="th" style="width: 80px">电脑流量</th>
                    <th class="th" style="width: 80px">手机流量</th>
                    <th class="th" style="width: 40px">排序</th>
                    <th class="th" style="width: 180px">发布日期</th>
                    <th class="th thlast">操作</th>
                </tr>
                <%System.Data.DataTable dt= Codes.Content.getList("id,title,author,click_pc,click_wap,cover,order,addtime", Request["group"], Request["title"], int.Parse(string.IsNullOrEmpty(Request["p"])?"1":Request["p"]), 10); %>
                <%foreach(System.Data.DataRow dr in dt.Rows) {%>
                <tr>
                    <td class="td">
                        <input type="checkbox" name="idbox" value="<%=dr["id"] %>" /></td>
                    <td class="td"><%=dr["groupName"] %></td>
                    <td class="td"><%=string.IsNullOrEmpty(dr["cover"].ToString())?"":"<img src='../Images/picture.png' style='vertical-align:middle;margin-top:-5px' /> " %><%=dr["title"] %></td>
                    <td class="td"><%=dr["click_pc"] %></td>
                    <td class="td"><%=dr["click_wap"] %></td>
                    <td class="td" style="padding:0">
                        <input type="text" class="order" value="<%=dr["order"] %>" data-id="<%=dr["id"] %>" onchange="changeOrder(this)" /></td>
                    <td class="td"><%=Codes.h.ManuTime(dr["addtime"].ToString())%></td>
                    <td class="td tdlast txtcenter">
                        <a href="updateContent.aspx?actionType=update&id=<%=dr["id"] %>">
                            <img src="../Images/edit.png" class="tool_edit" />编辑</a>
                        <a href="javascript:void(0);" onclick="deletes(<%=dr["id"] %>)">
                            <img src="../Images/delete.png" class="tool_delete" />删除</a></td>
                </tr>
                <%} %>
            </table>
            <div class="tcdPageCode"></div>
            <script src="../Scripts/jquery.page.js"></script>
            <script>
                $(".tcdPageCode").createPage({
                    pageCount: '<%=Math.Ceiling((double)Codes.Content.getListCount(Request["group"],Request["title"])/10)%>',
                    current: '<%=string.IsNullOrEmpty(Request["p"])?"1":Request["p"]%>',
                    backFn: function (p) {
                        window.location.href = "?p=" + p+"&group=<%=Request["group"]%>&title=<%=Request["title"]%>";
                    }
                });
            </script>
        </div>
    </div>
    <!--#include file='../Include/footer.html'-->
</body>
</html>
